<%@page import="java.sql.Date"%>
<%@page import="java.sql.ResultSet"%>
<%@page import="java.text.SimpleDateFormat"%>
<%@page import="java.util.regex.Pattern"%>
<%@page import="com.logistics.database.Distributiondatabase"%>
<%@ page language="java" import="java.util.*" pageEncoding="utf-8"%>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
  <head>
    <base href="<%=basePath%>">
    
    <title>My JSP 'Getmissionbydate.jsp' starting page</title>
    
	<meta http-equiv="pragma" content="no-cache">
	<meta http-equiv="cache-control" content="no-cache">
	<meta http-equiv="expires" content="0">    
	<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
	<meta http-equiv="description" content="This is my page">
	<!--
	<link rel="stylesheet" type="text/css" href="styles.css">
	-->

  </head>
  
  <body>
   <%
   		String begin_time_string = request.getParameter("begin_time");
   		String end_time_string = request.getParameter("end_time");
   		//System.out.println("begin_time_string:"+begin_time_string);
   		//System.out.println("end_time_string:"+end_time_string);
   		java.util.Date tempdate=new java.util.Date();
   		SimpleDateFormat simpleDateFormat=new SimpleDateFormat("yyyy-MM-dd");
   		tempdate=simpleDateFormat.parse(begin_time_string);
   		java.sql.Date begin_time=new java.sql.Date(tempdate.getTime());
   		tempdate=simpleDateFormat.parse(end_time_string);
   		java.sql.Date end_time=new java.sql.Date(tempdate.getTime());
   		int mission_sum=0;
   		int product_sum=0;
   		double money_sum=0;
   		Distributiondatabase distributiondatabase=new Distributiondatabase();
  		ResultSet resultSet = distributiondatabase.getMissions();
  		//System.out.println("!!!");
   		while(resultSet.next())
   		 {
   			 //System.out.println("!"+resultSet.getString("mission_state"));
   		 	if("已完成".equals(resultSet.getString("mission_state"))&&"送货".equals(resultSet.getString("mission_type")))
   		 	{
   		 		//System.out.println("!");
   		 		java.sql.Date mission_Date=resultSet.getDate("mission_date");
   		 		//System.out.println("mission_date:"+mission_Date.toString());
   		 		//System.out.println("start_date:"+begin_time.toString());
   		 		//System.out.println("end_date:"+end_time.toString());
   		 		if(mission_Date.getTime()<=end_time.getTime()&&mission_Date.getTime()>=begin_time.getTime())
   		 		{
   		 			mission_sum+=1;
   		 			int number=resultSet.getInt("product_number");
   		 			System.out.println("number:"+number);
   		 			product_sum+=number;
   		 			int id=resultSet.getInt("product_id");
   		 			System.out.println("id:"+id);
   		 			ResultSet tempResultSet=distributiondatabase.productsQuery(id);
   		 			tempResultSet.next();
   		 			double price=tempResultSet.getDouble("price");
   		 			System.out.println("price:"+price);
   		 			money_sum+=number*price;
   		 		}
   		 	}
   		 }
   		String data=mission_sum+","+product_sum+","+money_sum;
   		response.setContentType("text/xml;charset=UTF-8");
		response.setHeader("Cache-Control", "no-cache");	
		//System.out.println(data); 
    	response.getWriter().write(data);
    	response.getWriter().close();
    %>
  </body>
</html>
